package com.buka.recipe.system.controller;

import com.buka.recipe.common.result.Result;
import com.buka.recipe.common.result.ResultGenerator;
import com.buka.recipe.system.entity.Role;
import com.buka.recipe.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    private final RoleService roleService;

    @Autowired
    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    @GetMapping("/list")
    public Result<?> list(@RequestParam(required = false) String name,
                          @RequestParam(required = false, defaultValue = "0") Integer current,
                          @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Page<Role> roles = roleService.getAll(name, current, pageSize);
        return ResultGenerator.genSuccessResult(roles);
    }

}
